package com.example.computer_exam_training_sys.controller;

import com.example.computer_exam_training_sys.entity.UserFollow;
import com.example.computer_exam_training_sys.service.UserFollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/follow")
@CrossOrigin
public class UserFollowController {

    @Autowired
    private UserFollowService userFollowService;

    // 添加关注关系
    // 示例访问: POST http://localhost:8080/follow/add
    @PostMapping("/add")
    public Integer addFollow(@RequestBody UserFollow userFollow) {
        int result = userFollowService.insert(userFollow);
        return result;
    }

    // 查询某用户的关注列表
    // 示例访问: GET http://localhost:8080/follow/list?userId=1
    @GetMapping("/list")
    public List<UserFollow> getFollows(@RequestParam Integer userId) {
        return userFollowService.selectByUserId(userId);
    }

    // 取消关注关系
    // 示例访问: DELETE http://localhost:8080/follow/delete?userId=1&followedUserId=2
    @DeleteMapping("/delete")
    public String deleteFollow(@RequestParam Integer userId, @RequestParam Integer followedUserId) {
        int result = userFollowService.delete(userId, followedUserId);
        return result > 0 ? "取消关注成功" : "取消关注失败";
    }
    // 查询所有用户关注记录
// 示例访问: GET http://localhost:8080/follow/all
    @GetMapping("/all")
    public List<UserFollow> getAllFollows() {
        return userFollowService.selectAll();
    }

}
